<?php
namespace app\index\model;
use think\Model;
class Cate extends Model
{
    public function getAllChildren($id,$t=true){
        static $arr=array();
        $cates=$this->select();
        if($t){
            $arr[]=$id;
            $t=false;
        }
        else{
            foreach ($cates as $k => $v){
                if($v['pid']==$id){
                    $arr[]=$v['id'];
                    $this->getAllChildren($v['id'],$t);
                }
            }

        }
        return implode(',',$arr);
    }

    public function getParentId($cateid,$t=true)
    {
        static $arr=array();
        if($t){
            $arr[]=(int)$cateid;
            $t=false;
        }

        $parent=$this->where('id',$cateid)->find();
        $pid=$parent['pid'];
        if($pid!==0){
            $arr[]=(int)$pid;
            $cateid=(int)$pid;
            $this->getParentId($cateid,$t);
        }
        return array_reverse($arr);
    }


}